package top.lishuoboy.hutool.captcha;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.core.lang.Console;

import java.io.File;
import java.io.IOException;

public class CaptchaTest {

    public static void main(String[] args) throws IOException {
        //定义图形验证码的长和宽
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(100, 50);

        String projectDir = new File("").getCanonicalPath();

        CaptchaUtil.createShearCaptcha(100, 50).write(projectDir + "/tmp/captcha1.png");
        CaptchaUtil.createCircleCaptcha(100, 50).write(projectDir + "/tmp/captcha2.png");
        CaptchaUtil.createGifCaptcha(100, 50).write(projectDir + "/tmp/captcha3.gif");

        //图形验证码写出，可以写出到文件，也可以写出到流
        lineCaptcha.write(projectDir + "/tmp/captcha.png");
        //输出code
        Console.log(lineCaptcha.getCode());
        //验证图形验证码的有效性，返回boolean值
        Console.log(lineCaptcha.verify("1234"));

        //重新生成验证码
        lineCaptcha.createCode();
        lineCaptcha.write(projectDir + "/tmp/captcha.png");
        //新的验证码
        Console.log(lineCaptcha.getCode());
        //验证图形验证码的有效性，返回boolean值
        Console.log(lineCaptcha.verify("1234"));
    }
}
